package wg.forecast
{
	import flash.events.*;
	
	public class WGForecast extends EventDispatcher
	{
		import wg.xml.*;
		import mx.collections.ArrayCollection;

		public var data:XML = new XML();
		
		private var link:String = "";
		private var xml:WGXml = new WGXml();
		
		public function WGForecast()
		{
			this.xml = new WGXml();
			this.xml.addEventListener("XMLLoaded", parseData);
			this.xml.addEventListener("XMLError", errorLoadingXML);
		}
		public function send(code:String, days:int=5):void {
			this.link = "http://request.webgurucms.com/request.php?wcode=" + code + "&cc=*&dayf=" + days.toString() + "&link=xoap&par=1072604315&key=def41c3ef8225c23";
			this.xml.sendXML(this.link);
		}
		
		public function requestList(url:String=null):void {
			if (url == null)this.link = "http://www.webgurucms.com/resources/weather/ondra-codes.xml";
			else this.link = url;
			this.xml.sendXML(this.link);
		}
		
		private function parseData(e:Event):void {
			this.data = e.target.xml;
			dispatchEvent(new Event("dataParsed"));
		}
		
		private function errorLoadingXML(e:Event):void {
			dispatchEvent(new Event("dataError"));
		}
	}
}